home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SIHelper.cpp
-
- Contains: xxx put contents here xxx
-
- Owned by: Nick Pilch
-
- Copyright:
-
- Change History (most recent first):
-
- <3> 1/8/96 TJ Removed the duplicate function GetSLongAttr
- that caused a build break on 68K.
- <2> 5/01/96 NP 1269380: Call ODDisposeAppleEvent, not
- AEDisposeDesc to eliminate memory leak.
-
- To Do:
- */
-
- /*
- File: SIHelper.cpp
-
- Contains: Implementation of Mac C++ version of SemanticInterface helper
- class
-
- Owned by: Nick Pilch
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
-
- In Progress:
- */
-
- #ifndef SOM_ODSession_xh
- #include "ODSessn.xh"
- #endif
-
- #ifndef SOM_ODSemanticInterface_xh
- #include "SemtIntB.xh"
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include "NamRslvr.xh"
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include "ODAplEvt.xh"
- #endif
-
- #ifndef SOM_ODOSLToken_xh
- #include "ODOSLTkn.xh"
- #endif
-
- #ifndef _SIHELPER_
- #include "SIHelper.h"
- #endif
-
- #ifndef _SIHSHTBL_
- #include "SIHshTbl.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef __AEOBJECTS__
- #include "AEObjects.h"
- #endif
-
- #ifndef __ERRORS__
- #include "Errors.h"
- #endif
-
- #ifndef __ODDESUTL__
- #include "ODDesUtl.h"
- #endif
-
- #ifndef __SEUTILS__
- #include "SEUtils.h"
- #endif
-
- #pragma segment SIHelper
-
- //==============================================================================
- // Implementation Notes
- //==============================================================================
-
- /*
- Cover routines for AppleEvent Manager and OSL routines try to mimic these
- routines exactly. I consulted the source code for the AE Mgr and the OSL to do
- this.
- */
-
- //==============================================================================
- // Local Types
- //==============================================================================
-
- struct SIGenericKey
- {
- ODDescType key1;
- ODDescType key2;
- };
-
- struct SIGenericValue
- {
- UniversalProcPtr handler;
- ODSLong refCon;
- ODBoolean fromTypeIsDesc;
- };
-
- struct SIEventHandlerKey
- {
- ODEventClass eventClass;
- ODEventID eventID;
- };
-
- struct SIEventHandlerValue
- {
- ODEventHandlerUPP handler;
- ODSLong refCon;
- };
-
- struct SIObjectAccessorKey
- {
- ODDescType desiredClass;
- ODDescType containerType;
- };
-
- struct SIObjectAccessorValue
- {
- ODObjectAccessorUPP accessor;
- ODSLong refCon;
- };
-
- struct SICoercionHandlerKey
- {
- ODDescType fromType;
- ODDescType toType;
- };
-
- struct SICoercionHandlerValue
- {
- ODCoercionHandlerUPP handler;
- ODSLong refCon;
- ODBoolean fromTypeIsDesc;
- };
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- // for hash tables
-
- const ODULong kNumInitialSIHashTableEntries = 8;
-
- const ODBoolean kNotInSystemHeap = false;
-
- const ODBoolean kODSEUnusedBoolParam = 0;
-
- //------------------------------------------------------------------------------
- // Functions
- //------------------------------------------------------------------------------
-
- //------------------------------------------------------------------------------
- // NewSIHashTable
- //
- // Creates, initializes and returns new SIHashTable object.
- //------------------------------------------------------------------------------
-
- static SIHashTable* NewSIHashTable()
- {
- SIHashTable* table = new SIHashTable;
- table->Initialize(kNumInitialSIHashTableEntries, sizeof(SIEventHandlerKey),
- sizeof(SIEventHandlerValue), kNotInSystemHeap);
- return table;
- }
-
- //------------------------------------------------------------------------------
- // NewSICoercionHashTable
- //
- // Creates, initializes and returns new SIHashTable object.
- //------------------------------------------------------------------------------
-
- static SIHashTable* NewSICoercionHashTable()
- {
- SIHashTable* table = new SIHashTable;
- table->Initialize(kNumInitialSIHashTableEntries, sizeof(SICoercionHandlerKey),
- sizeof(SICoercionHandlerValue), kNotInSystemHeap);
- return table;
- }
-
- //------------------------------------------------------------------------------
- // ThrowIfBadHandler
- //
- // Throws paramErr if the handler is odd or null.
- //------------------------------------------------------------------------------
-
- static void ThrowIfBadHandler(UniversalProcPtr proc)
- {
- if ((proc == (UniversalProcPtr)kODNULL)
- || ((ODULong)proc & 1))
- THROW(paramErr);
- }
-
- //------------------------------------------------------------------------------
- // ReturnCallbackFuncCaller
- //------------------------------------------------------------------------------
-
- //extern "C" {
-
- //CallbackCallerProc ReturnCallbackFuncCaller(OSLCallbackSelector whichCallback);
-
- //}
-
- //==============================================================================
- // SIHelper
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // SIHelper::SIHelper
- //------------------------------------------------------------------------------
-
- SIHelper::SIHelper()
- {
- fEventHandlerTable = kODNULL;
- fObjectAccessorTable = kODNULL;
- fCoercionHandlerTable = kODNULL;
-
- fCountProcPtr = (ODCountUPP)kODNULL;
- fCompareProcPtr = (ODCompareUPP)kODNULL;
- fDisposeTokenProcPtr = (ODDisposeTokenUPP)kODNULL;
- fErrDescProcPtr = (ODGetErrDescUPP)kODNULL;
- fGetMarkTokenProcPtr = (ODGetMarkTokenUPP)kODNULL;
- fMarkProcPtr = (ODMarkUPP)kODNULL;
- fAdjustMarksProcPtr = (ODAdjustMarksUPP)kODNULL;
- fPreDispatchProcPtr = (ODPreDispatchUPP)kODNULL;
-
- fTokenInquiryProc = (ODTokenInquiryUPP)kODNULL;
-
- fOSLSupportFlags = kAEIDoMinimum;
-
- fSemanticInterface = (ODSemanticInterface*)kODNULL;
- // fNameResolver = kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InitSIHelper
- //------------------------------------------------------------------------------
-
- void SIHelper::InitSIHelper(ODSession* session, ODSemanticInterface* helpee)
- {
- fSemanticInterface = helpee;
-
- fEventHandlerTable = NewSIHashTable();
- fObjectAccessorTable = NewSIHashTable();
- fCoercionHandlerTable = NewSICoercionHashTable();
-
- fNameResolver = session->GetNameResolver(somGetGlobalEnvironment());
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::~SIHelper
- //------------------------------------------------------------------------------
-
- SIHelper::~SIHelper()
- {
- if ( fEventHandlerTable )
- delete fEventHandlerTable;
-
- if ( fObjectAccessorTable )
- delete fObjectAccessorTable;
-
- if ( fCoercionHandlerTable )
- delete fCoercionHandlerTable;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::ThrowProcNotFound
- //
- // Throws the error code according to the type of proc that wasn't found.
- // errAEHandlerNotFound for coercion handlers and event handlers and
- // errAEAccessorNotFound for object accessors.
- //------------------------------------------------------------------------------
-
- void SIHelper::ThrowProcNotFound(SIHashTable* table)
- {
- if (table == fObjectAccessorTable)
- THROW(errAEAccessorNotFound);
- else
- THROW(errAEHandlerNotFound);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::AddToTable
- //
- // Adds a proc ptr to one of our SIHashTables. fromTypeIsDesc is only used
- // when adding a coercion handler. fCoercionHandlerTable knows this.
- //
- // For event handlers: key1 = AEEventClass, key2 = AEEventID
- // For coercion handlers: key1 = fromType, key2 = toType
- // For object accessors: key1 = desiredClass, key2 = containerClass
- //------------------------------------------------------------------------------
-
- void SIHelper::AddToTable(DescType key1, DescType key2,
- UniversalProcPtr handler,
- ODSLong handlerRefCon,
- ODBoolean fromTypeIsDesc,
- SIHashTable* table)
- {
- SIGenericKey theKey;
- SIGenericValue theValue;
-
- ThrowIfBadHandler(handler);
-
- theKey.key1 = key1;
- theKey.key2 = key2;
-
- theValue.handler = handler;
- theValue.refCon = handlerRefCon;
- theValue.fromTypeIsDesc = fromTypeIsDesc;
-
- table->ReplaceEntry((ODKeyPtr)&theKey, (ODEntryPtr)&theValue);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::RetrieveFromTable
- //
- // Retrieves a proc ptr from one of our SIHashTables. fromTypeIsDesc is only used
- // when adding a coercion handler. fCoercionHandlerTable knows this.
- //
- // For event handlers: key1 = AEEventClass, key2 = AEEventID
- // For coercion handlers: key1 = fromType, key2 = toType
- // For object accessors: key1 = desiredClass, key2 = containerClass
- //------------------------------------------------------------------------------
-
- void SIHelper::RetrieveFromTable(DescType key1, DescType key2,
- UniversalProcPtr* handler,
- ODSLong* handlerRefCon,
- ODBoolean* fromTypeIsDesc,
- SIHashTable* table)
- {
- SIGenericKey theKey;
- SIGenericValue theValue;
-
- theKey.key1 = key1;
- theKey.key2 = key2;
-
- if (table->GetValue((ODKeyPtr)&theKey, (ODEntryPtr)&theValue) != kODFalse)
- {
- *handler = theValue.handler;
- *handlerRefCon = theValue.refCon;
- *fromTypeIsDesc = theValue.fromTypeIsDesc;
- }
- else
- ThrowProcNotFound(table);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::RemoveFromTable
- //
- // Removes a proc ptr from one of our SIHashTables. fromTypeIsDesc is only
- // used when adding a coercion handler. fCoercionHandlerTable knows this.
- //
- // For event handlers: key1 = AEEventClass, key2 = AEEventID
- // For coercion handlers: key1 = fromType, key2 = toType
- // For object accessors: key1 = desiredClass, key2 = containerClass
- //------------------------------------------------------------------------------
-
- void SIHelper::RemoveFromTable(DescType key1,
- DescType key2,
- UniversalProcPtr handler,
- SIHashTable* table)
- {
- SIGenericKey theKey;
- SIGenericValue theValue;
- ODBoolean result;
-
- theKey.key1 = key1;
- theKey.key2 = key2;
-
- result = table->GetValue((ODKeyPtr)&theKey, (ODEntryPtr)&theValue);
-
- if (result)
- {
- if (theValue.handler == (UniversalProcPtr)kODNULL
- || theValue.handler == handler)
- table->RemoveEntry((ODKeyPtr)&theKey);
- else
- ThrowProcNotFound(table);
- }
- else
- ThrowProcNotFound(table);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallEventHandler
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallEventHandler(
- ODPart* thePart,
- ODAppleEvent* theODAppleEvent,
- ODAppleEvent* reply)
- {
- OSErr result = noErr;
- ODSLong handlerRefCon;
- AEEventClass eventClass;
- AEEventID eventID;
- ODEventHandlerUPP proc;
- AppleEvent realEvent;
-
- TRY
- ODDescToAEDesc(theODAppleEvent, &realEvent);
- eventClass = (AEEventClass)GetSLongAttr(&realEvent,
- keyEventClassAttr);
- eventID = (AEEventID)GetSLongAttr(&realEvent,
- keyEventIDAttr);
-
- if (this->LookupEventHandler(eventClass, eventID, &proc,
- &handlerRefCon))
- {
- TRY // 1245972 - don't need to put exception handling here anymore.
- result = (OSErr)CallODEventHandlerProc(proc, thePart,
- theODAppleEvent,
- reply,
- handlerRefCon);
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
- }
- else
- result = errAEEventNotHandled;
-
- ODDisposeAppleEvent(&realEvent);
- CATCH_ALL
- result = errAEEventNotHandled;
- ENDTRY
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallPredispatchProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallPredispatchProc(
- ODPart* thePart,
- ODAppleEvent* theODAppleEvent,
- ODAppleEvent* reply)
- {
- OSErr error;
-
- if (fPreDispatchProcPtr)
- error = CallODPreDispatchProc(fPreDispatchProcPtr, thePart,
- theODAppleEvent, reply,
- fPreDispatchProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallCoercionHandler
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallCoercionHandler(
- ODPart* thePart,
- ODDesc* theODDesc,
- ODDescType toType,
- ODDesc* retDesc)
- {
- OSErr result;
- ODCoercionHandlerUPP proc;
- ODSLong refCon;
- ODBoolean fromTypeIsDesc;
- AEDesc realInDesc;
- AEDesc realOutDesc;
-
- ODDescToAEDesc(theODDesc, &realInDesc);
- ODDescToAEDesc(retDesc, &realOutDesc);
- if (this->LookupCoercionHandler(realInDesc.descriptorType, toType,
- &proc, &refCon, &fromTypeIsDesc))
- {
- if (fromTypeIsDesc)
- { // 1245972 - don't need to put exception handling here anymore.
- TRY
- result = (OSErr)CallODDescCoercionHandlerProc(
- (ODDescCoercionHandlerUPP)proc,
- thePart,
- theODDesc, toType,
- refCon, retDesc);
-
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
- }
- else
- {
- ODLockHandle((ODHandle)realInDesc.dataHandle);
- ODPtr dataPtr = *((ODPtr**)(realInDesc.dataHandle));
- ODSize dataSize = ODGetHandleSize((ODHandle)realInDesc.dataHandle);
-
- // 1245972 - don't need to put exception handling here anymore.
- TRY
- result = (OSErr)CallODPtrCoercionHandlerProc(
- (ODPtrCoercionHandlerUPP)proc,
- thePart,
- realInDesc.descriptorType,
- dataPtr, dataSize, toType,
- refCon, retDesc);
-
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
-
- ODUnlockHandle((ODHandle)realInDesc.dataHandle);
- }
- }
- else
- result = errAECoercionFail;
-
- AEDisposeDesc(&realInDesc);
- AEDisposeDesc(&realOutDesc);
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallObjectAccessor
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallObjectAccessor(
- ODPart* thePart,
- ODDescType desiredClass,
- ODOSLToken* container,
- ODDescType containerClass,
- ODDescType form,
- ODDesc* selectionData,
- ODOSLToken* value)
- {
- OSErr result = noErr;
- ODSLong handlerRefCon;
- ODObjectAccessorUPP proc;
- ODDesc* userToken;
- AEDesc userAEToken;
-
- TRY
-
- /* THIS IS THE REAL CODE THAT SHOULD BE HERE. UNTIL WE ARE ALLOWED TO */
- /* PASS THE SESSION TO INITSIHELPER, WE LIFT CODE FROM ELSEWHERE AND */
- /* PLACE IT IN-LINE HERE. */
-
- userToken = fNameResolver->GetUserToken(somGetGlobalEnvironment(),
- container);
- ODDescToAEDesc(userToken, &userAEToken);
- DescType descType = userAEToken.descriptorType;
- (void)AEDisposeDesc( &userAEToken );
-
- if (this->LookupObjectAccessor(desiredClass,
- descType,
- &proc, &handlerRefCon))
- {
- // 1245972 - don't need to put exception handling here anymore.
- TRY
- result = (OSErr)CallODObjectAccessorProc(proc, thePart,
- desiredClass,
- container,
- containerClass,
- form, selectionData,
- value,
- handlerRefCon);
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
- }
- else
- result = errAEEventNotHandled;
- CATCH_ALL
- result = errAEEventNotHandled;
- ENDTRY
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallCompareProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallCompareProc(
- ODPart* thePart,
- ODDescType oper,
- ODOSLToken* obj1,
- ODOSLToken* obj2,
- ODBoolean* result)
- {
- OSErr error;
-
- if (fCompareProcPtr)
- error = CallODCompareProc(fCompareProcPtr, thePart, oper,
- obj1, obj2, result, fCompareProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallCountProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallCountProc(
- ODPart* thePart,
- ODDescType desiredType,
- ODDescType containerClass,
- ODOSLToken* container,
- ODSLong* result)
- {
- OSErr error;
-
- if (fCountProcPtr)
- error = (OSErr)CallODCountProc(fCountProcPtr, thePart, desiredType,
- containerClass, container,
- result, fCountProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallDisposeTokenProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallDisposeTokenProc(
- ODPart* thePart,
- ODOSLToken* unneededToken)
- {
- OSErr error;
-
- if (fDisposeTokenProcPtr)
- error = (OSErr)CallODDisposeTokenProc(fDisposeTokenProcPtr, thePart,
- unneededToken,
- fDisposeTokenProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallGetErrDescProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallGetErrDescProc(
- ODPart* thePart,
- ODDesc** errDesc)
- {
- OSErr error;
-
- if (fErrDescProcPtr)
- error = (OSErr)CallODGetErrDescProc(fErrDescProcPtr, thePart, errDesc,
- fErrDescProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallGetMarkTokenProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallGetMarkTokenProc(
- ODPart* thePart,
- ODOSLToken* dContainerToken,
- ODDescType containerClass,
- ODOSLToken* result)
- {
- OSErr error;
-
- if (fGetMarkTokenProcPtr)
- error = (OSErr)CallODGetMarkTokenProc(fGetMarkTokenProcPtr, thePart,
- dContainerToken, containerClass,
- result,
- fGetMarkTokenProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallMarkProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallMarkProc(
- ODPart* thePart,
- ODOSLToken* dToken,
- ODOSLToken* markToken,
- ODSLong index)
- {
- OSErr error;
-
- if (fMarkProcPtr)
- error = (OSErr)CallODMarkProc(fMarkProcPtr, thePart, dToken,
- markToken, index,
- fMarkProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::CallAdjustMarksProc
- //------------------------------------------------------------------------------
-
- ODError SIHelper::CallAdjustMarksProc(
- ODPart* thePart,
- ODSLong newStart,
- ODSLong newStop,
- ODOSLToken* markToken)
- {
- OSErr error;
-
- if (fAdjustMarksProcPtr)
- error = (OSErr)CallODAdjustMarksProc(fAdjustMarksProcPtr, thePart,
- newStart, newStop, markToken,
- fAdjustMarksProcPtrRefCon);
- else
- error = errAEEventNotHandled;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallObjectAccessor
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallObjectAccessor(ODDescType desiredClass,
- ODDescType containerType,
- ODObjectAccessorUPP theAccessor,
- ODSLong accessorRefcon)
- {
- this->AddToTable(desiredClass, containerType, (UniversalProcPtr)theAccessor,
- accessorRefcon, kODSEUnusedBoolParam,
- fObjectAccessorTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::GetObjectAccessor
- //------------------------------------------------------------------------------
-
- void SIHelper::GetObjectAccessor(ODDescType desiredClass,
- ODDescType containerType,
- ODObjectAccessorUPP* theAccessor,
- ODSLong* accessorRefcon)
- {
- ODBoolean unusedBoolParam;
-
- this->RetrieveFromTable(desiredClass, containerType,
- (UniversalProcPtr*)theAccessor, accessorRefcon,
- &unusedBoolParam, fObjectAccessorTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::RemoveObjectAccessor
- //------------------------------------------------------------------------------
-
- void SIHelper::RemoveObjectAccessor(ODDescType desiredClass,
- ODDescType containerType,
- ODObjectAccessorUPP theAccessor)
- {
- this->RemoveFromTable(desiredClass, containerType, (UniversalProcPtr)theAccessor,
- fObjectAccessorTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallCompareProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallCompareProc(ODCompareUPP compareProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)compareProc);
-
- fCompareProcPtr = compareProc;
- fCompareProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallCountProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallCountProc(ODCountUPP countProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)countProc);
-
- fCountProcPtr = countProc;
- fCountProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallDisposeTokenProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallDisposeTokenProc(ODDisposeTokenUPP disposeTokenProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)disposeTokenProc);
-
- fDisposeTokenProcPtr = disposeTokenProc;
- fDisposeTokenProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallGetMarkTokenProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallGetMarkTokenProc(ODGetMarkTokenUPP getMarkTokenProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)getMarkTokenProc);
-
- fGetMarkTokenProcPtr = getMarkTokenProc;
- fGetMarkTokenProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallMarkProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallMarkProc(ODMarkUPP markProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)markProc);
-
- fMarkProcPtr = markProc;
- fMarkProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallAdjustMarksProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallAdjustMarksProc(ODAdjustMarksUPP adjustMarksProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)adjustMarksProc);
-
- fAdjustMarksProcPtr = adjustMarksProc;
- fAdjustMarksProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallGetErrDescProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallGetErrDescProc(ODGetErrDescUPP errorDescProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)errorDescProc);
-
- fErrDescProcPtr = errorDescProc;
- fErrDescProcPtrRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallTokenInquiryProc
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallTokenInquiryProc(ODTokenInquiryUPP tokenInquiryProc,
- ODSLong refCon)
- {
- ThrowIfBadHandler((UniversalProcPtr)tokenInquiryProc);
-
- fTokenInquiryProc = tokenInquiryProc;
- fTokenInquiryProcRefCon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallEventHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallEventHandler( ODEventClass theAEEventClass,
- ODEventID theAEEventID,
- ODEventHandlerUPP handler,
- ODSLong handlerRefCon)
- {
- this->AddToTable(theAEEventClass, theAEEventID, (UniversalProcPtr)handler,
- handlerRefCon, kODSEUnusedBoolParam,
- fEventHandlerTable);
- // fSemanticInterface->ForwardEvent(somGetGlobalEnvironment(), (ODBoolean)mode,
- // theAEEventClass, theAEEventID);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::RemoveEventHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::RemoveEventHandler(ODEventClass theAEEventClass,
- ODEventID theAEEventID,
- ODEventHandlerUPP handler)
- {
- this->RemoveFromTable(theAEEventClass, theAEEventID, (UniversalProcPtr)handler,
- fEventHandlerTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::GetEventHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::GetEventHandler(ODEventClass theAEEventClass,
- ODEventID theAEEventID,
- ODEventHandlerUPP* handler,
- ODSLong* handlerRefcon)
- {
- ODBoolean unusedBoolParam;
-
- this->RetrieveFromTable(theAEEventClass, theAEEventID,
- (UniversalProcPtr*)handler, handlerRefcon,
- &unusedBoolParam, fEventHandlerTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallCoercionHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallCoercionHandler(ODDescType fromType,
- ODDescType toType,
- ODCoercionHandlerUPP handler,
- ODSLong handlerRefCon,
- ODBoolean fromTypeIsDesc)
- {
- this->AddToTable(fromType, toType, (UniversalProcPtr)handler, handlerRefCon,
- fromTypeIsDesc, fCoercionHandlerTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::RemoveCoercionHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::RemoveCoercionHandler(ODDescType fromType,
- ODDescType toType,
- ODCoercionHandlerUPP handler)
- {
- this->RemoveFromTable(fromType, toType, (UniversalProcPtr)handler,
- fCoercionHandlerTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::GetCoercionHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::GetCoercionHandler(ODDescType fromType,
- ODDescType toType,
- ODCoercionHandlerUPP* handler,
- ODSLong* handlerRefcon,
- ODBoolean* fromTypeIsDesc)
- {
- this->RetrieveFromTable(fromType, toType, (UniversalProcPtr*)handler, handlerRefcon,
- fromTypeIsDesc, fCoercionHandlerTable);
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::InstallSpecialHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::InstallSpecialHandler(AEKeyword functionClass,
- ODSpecialHandlerUPP handler,
- ODSLong refCon)
- {
- switch( functionClass )
- {
- case keyAECountProc:
- fCountProcPtr = (ODCountUPP)handler;
- fCountProcPtrRefCon = refCon;
- break;
- case keyAECompareProc:
- fCompareProcPtr = (ODCompareUPP)handler;
- fCompareProcPtrRefCon = refCon;
- break;
- case keyDisposeTokenProc:
- fDisposeTokenProcPtr = (ODDisposeTokenUPP)handler;
- fDisposeTokenProcPtrRefCon = refCon;
- break;
- case keyAEGetErrDescProc:
- fErrDescProcPtr = (ODGetErrDescUPP)handler;
- fErrDescProcPtrRefCon = refCon;
- break;
- case keyAEMarkTokenProc:
- fGetMarkTokenProcPtr = (ODGetMarkTokenUPP)handler;
- fGetMarkTokenProcPtrRefCon = refCon;
- break;
- case keyAEMarkProc:
- fMarkProcPtr = (ODMarkUPP)handler;
- fMarkProcPtrRefCon = refCon;
- break;
- case keyAEAdjustMarksProc:
- fAdjustMarksProcPtr = (ODAdjustMarksUPP)handler;
- fAdjustMarksProcPtrRefCon = refCon;
- break;
- case keyPreDispatch:
- fPreDispatchProcPtr = (ODPreDispatchUPP)handler;
- fPreDispatchProcPtrRefCon = refCon;
- fSemanticInterface->UsingPredispatchProc(somGetGlobalEnvironment(),
- kODTrue);
- // fMessageInterface->PreHandlerAdded((ODPart*)this->GetBase(),
- // (ODPreDispatchUPP)handler,
- // refCon);
- break;
- default:
- THROW( errAENotASpecialFunction );
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::RemoveSpecialHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::RemoveSpecialHandler(AEKeyword functionClass,
- ODSpecialHandlerUPP handler)
- {
- switch( functionClass )
- {
- case keyAECountProc:
- if (handler == (ODSpecialHandlerUPP)fCountProcPtr)
- fCountProcPtr = (ODCountUPP)kODNULL;
- break;
- case keyAECompareProc:
- if (handler == (ODSpecialHandlerUPP)fCompareProcPtr )
- fCompareProcPtr = (ODCompareUPP)kODNULL;
- break;
- case keyDisposeTokenProc:
- if (handler == (ODSpecialHandlerUPP)fDisposeTokenProcPtr )
- fDisposeTokenProcPtr = (ODDisposeTokenUPP)kODNULL;
- break;
- case keyAEGetErrDescProc:
- if (handler == (ODSpecialHandlerUPP)fErrDescProcPtr )
- fErrDescProcPtr = (ODGetErrDescUPP)kODNULL;
- break;
- case keyAEMarkTokenProc:
- if (handler == (ODSpecialHandlerUPP)fGetMarkTokenProcPtr )
- fGetMarkTokenProcPtr = (ODGetMarkTokenUPP)kODNULL;
- break;
- case keyAEMarkProc:
- if (handler == (ODSpecialHandlerUPP)fMarkProcPtr )
- fMarkProcPtr = (ODMarkUPP)kODNULL;
- break;
- case keyAEAdjustMarksProc:
- if (handler == (ODSpecialHandlerUPP)fAdjustMarksProcPtr )
- fAdjustMarksProcPtr = (ODAdjustMarksUPP)kODNULL;
- break;
- case keyPreDispatch:
- if (handler == (ODSpecialHandlerUPP)fPreDispatchProcPtr )
- {
- fPreDispatchProcPtr = (ODPreDispatchUPP)kODNULL;
- fSemanticInterface->UsingPredispatchProc(somGetGlobalEnvironment(),
- kODFalse);
- // fMessageInterface->PreHandlerRemoved((ODPart*)this->GetBase(),
- // (ODPreDispatchUPP)handler,
- // fPreDispatchProcPtrRefCon);
- }
- break;
- default:
- THROW( errAENotASpecialFunction );
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::GetSpecialHandler
- //------------------------------------------------------------------------------
-
- void SIHelper::GetSpecialHandler(AEKeyword functionClass,
- ODSpecialHandlerUPP* handler,
- ODSLong* refCon)
- {
- switch( functionClass )
- {
- case keyAECountProc:
- *handler = (ODSpecialHandlerUPP)fCountProcPtr;
- *refCon = fCountProcPtrRefCon;
- break;
- case keyAECompareProc:
- *handler = (ODSpecialHandlerUPP)fCompareProcPtr;
- *refCon = fCompareProcPtrRefCon;
- break;
- case keyDisposeTokenProc:
- *handler = (ODSpecialHandlerUPP)fDisposeTokenProcPtr;
- *refCon = fDisposeTokenProcPtrRefCon;
- break;
- case keyAEGetErrDescProc:
- *handler = (ODSpecialHandlerUPP)fErrDescProcPtr;
- *refCon = fErrDescProcPtrRefCon;
- break;
- case keyAEMarkTokenProc:
- *handler = (ODSpecialHandlerUPP)fGetMarkTokenProcPtr;
- *refCon = fGetMarkTokenProcPtrRefCon;
- break;
- case keyAEMarkProc:
- *handler = (ODSpecialHandlerUPP)fMarkProcPtr;
- *refCon = fMarkProcPtrRefCon;
- break;
- case keyAEAdjustMarksProc:
- *handler = (ODSpecialHandlerUPP)fAdjustMarksProcPtr;
- *refCon = fAdjustMarksProcPtrRefCon;
- break;
- case keyPreDispatch:
- *handler = (ODSpecialHandlerUPP)fPreDispatchProcPtr;
- *refCon = fPreDispatchProcPtrRefCon;
- break;
- default:
- THROW( errAENotASpecialFunction );
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::LookupEventHandler
- //------------------------------------------------------------------------------
-
- ODBoolean SIHelper::LookupEventHandler(ODEventClass eventClass,
- ODEventID eventID,
- ODEventHandlerUPP* handler,
- ODSLong* handlerRefcon)
- {
- SIEventHandlerValue value;
- ODBoolean result;
-
- result = HandlerLookup(eventClass, eventID , fEventHandlerTable,
- &value);
-
- if (result)
- {
- *handler = value.handler;
- *handlerRefcon = value.refCon;
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::LookupCoercionHandler
- //------------------------------------------------------------------------------
-
- ODBoolean SIHelper::LookupCoercionHandler(ODDescType fromType,
- ODDescType toType,
- ODCoercionHandlerUPP* handler,
- ODSLong* handlerRefcon,
- ODBoolean* fromTypeIsDesc)
- {
- SICoercionHandlerValue value;
- ODBoolean result;
-
- result = HandlerLookup(fromType, toType, fCoercionHandlerTable,
- (ODEntryPtr)&value);
-
- if (result)
- {
- *handler = value.handler;
- *handlerRefcon = value.refCon;
- *fromTypeIsDesc = value.fromTypeIsDesc;
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::LookupObjectAccessor
- //------------------------------------------------------------------------------
-
- ODBoolean SIHelper::LookupObjectAccessor(ODDescType desiredClass,
- ODDescType containerType,
- ODObjectAccessorUPP* theAccessor,
- ODSLong* accessorRefcon)
- {
- SIObjectAccessorValue value;
- ODBoolean result;
-
- result = HandlerLookup(desiredClass, containerType , fObjectAccessorTable,
- (ODEntryPtr)&value);
-
- if (result)
- {
- *theAccessor = value.accessor;
- *accessorRefcon = value.refCon;
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SIHelper::GetOSLContext
- //------------------------------------------------------------------------------
-
- //OSLContext* SIHelper::GetOSLContext()
- //{
- // return kODNULL;
- //}
-
- //------------------------------------------------------------------------------
- // SIHelper::HandlerLookup
- //------------------------------------------------------------------------------
-
- ODBoolean SIHelper::HandlerLookup(
- ODDescType key1,
- ODDescType key2,
- SIHashTable* theSIHashTable,
- void* theValue)
- {
- // This algorithm is duplicated in GetTableInfo in the AE Manager and
- // OSLClAcc.GetTableInfo. Here we go, duplicating it again.
-
- SIGenericKey key;
- ODBoolean result;
-
- key.key1 = key1;
- key.key2 = key2;
-
- result = theSIHashTable->GetValue((ODKeyPtr)&key, theValue);
- if (!result)
- {
- key.key1 = typeWildCard;
- result = theSIHashTable->GetValue((ODKeyPtr)&key, theValue);
- if (!result)
- {
- key.key1 = key1;
- key.key2 = typeWildCard;
- result = theSIHashTable->GetValue((ODKeyPtr)&key, theValue);
- if (!result)
- {
- key.key1 = typeWildCard;
- result = theSIHashTable->GetValue((ODKeyPtr)&key, theValue);
- }
- }
- }
-
- return result;
- }
- #if 0
- //------------------------------------------------------------------------------
- // GetTokenDescType
- //------------------------------------------------------------------------------
-
- ODDescType GetTokenDescType(ODOSLToken* token)
- {
- }
-
- //------------------------------------------------------------------------------
- // SetTokenDescType
- //------------------------------------------------------------------------------
-
- void SetTokenDescType(ODOSLToken* token, ODDescType type)
- {
- }
-
- //------------------------------------------------------------------------------
- // GetTokenDataHandle
- //------------------------------------------------------------------------------
-
- ODHandle GetTokenDataHandle(ODOSLToken* token)
- {
- }
-
- //------------------------------------------------------------------------------
- // SetTokenDataHandle
- //------------------------------------------------------------------------------
-
- void SetTokenDataHandle(ODOSLToken* token, ODHandle handle)
- {
- }
- #endif /* 0 */
-
-